require(['./config'],()=>{
    require(['template','cookie','jquery'],(template)=>{
        class dengLu{
            constructor(){
                this.User()
            }
            User(){
                $('.denglu').on('click',()=>{
                    let name = $('.username').val()
                    let password = $('.password').val()
                    let userList = localStorage.getItem('userList')
                    
                    if(userList){
                        userList = JSON.parse(userList)
                        let isExit = userList.some((user)=>{
                            return user.name === name && user.password === password
                        })
                        if(isExit){
                            // console.log(name)
                            $.cookie('loginUser',name, { expires: 7, path: '/' });
                            alert('登录成功，即将回到首页')
                            window.open('../')
                        }else{
                            alert('用户名或密码错误')
                        }
                    }else{
                        alert('请先注册')
                        location.replace('/html/register.html')
                    }
                })
            }
            
        }
        new dengLu()
    })
})